Skip to content

fix(cli): report packaged version in installed builds#153

Merged
benvinegar merged 1 commit intomodem-dev:mainfrom
ferologics:fix/version-installed-builds
Apr 1, 2026
Merged

fix(cli): report packaged version in installed builds#153
benvinegar merged 1 commit intomodem-dev:mainfrom
ferologics:fix/version-installed-builds

Conversation

@ferologics
Copy link
Copy Markdown
Contributor

@ferologics ferologics commented Mar 31, 2026

https://pi.dev/session/#801a09f0bbc28059312d25111ba2e0e2

Summary

  • report the CLI version from bundled package metadata instead of probing nearby manifests at runtime
  • share the unknown-version fallback constant with startup update notices
  • extend the prebuilt install smoke test to verify hunk --version

Testing

  • bun test test/cli.test.ts test/help-output.test.ts
  • bun run lint
  • bun run format:check
  • bun run check:pack
  • bun run build:bin >/dev/null && bun run ./scripts/stage-prebuilt-npm.ts >/dev/null && bun run check:prebuilt-pack && bun run ./scripts/smoke-prebuilt-install.ts

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 31, 2026

Greptile Summary

This PR fixes a long-standing issue where hunk --version would report an incorrect or unknown version in installed/compiled builds by replacing the fragile runtime filesystem walk with a build-time static JSON import of package.json. The version string is now embedded directly into the bundle at compile time, making it immune to filesystem layout differences in prebuilt installs.

Key changes:

  • src/core/version.ts: Strips out the multi-path existsSync/readFileSync probing loop and replaces it with import packageJson from "../../package.json" with { type: "json" }, embedding the version at bundle time.
  • src/core/updateNotice.ts: Removes the duplicated UNKNOWN_CLI_VERSION = "0.0.0-unknown" constant that previously shadowed the one in version.ts, now re-exported from the canonical location.
  • tsconfig.json: Adds resolveJsonModule: true to allow TypeScript to resolve the JSON import and provide type information.
  • scripts/smoke-prebuilt-install.ts: Refactors the repeated env object into a shared commandEnv variable and extends the prebuilt smoke test to assert that the installed binary's --version output matches the package version.
  • test/cli.test.ts: Adds a focused unit test for resolveCliVersion().

Confidence Score: 5/5

This PR is safe to merge — the change is a targeted, well-tested simplification with no runtime regressions.

All changed files are clean with no P0 or P1 issues. The approach (static JSON import at build time) is the idiomatic solution for this class of problem in Bun bundles. The deduplication of UNKNOWN_CLI_VERSION is strictly an improvement. The new smoke-test assertion closes the gap that originally caused the bug to go undetected. No breaking interface changes.

No files require special attention.

Important Files Changed

Filename Overview
src/core/version.ts Replaces runtime filesystem probing with a build-time static JSON import; exports UNKNOWN_CLI_VERSION for sharing. Clean and correct.
src/core/updateNotice.ts Removes duplicate UNKNOWN_CLI_VERSION constant, now imported from version.ts. Minimal and correct change.
test/cli.test.ts Adds a unit test for resolveCliVersion() — tautological in dev but validates no unexpected fallback to UNKNOWN_CLI_VERSION at test time.
scripts/smoke-prebuilt-install.ts Extracts commandEnv to a shared variable and adds --version output verification against the expected package version. Clean refactor.
tsconfig.json Adds resolveJsonModule: true to enable the new static JSON import in version.ts. Compatible with the existing moduleResolution: "bundler" setting.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["bun build --compile src/main.tsx"] -->|"bundles at build time"| B["package.json version\nembedded in binary"]
    B --> C["src/core/version.ts\nimport packageJson from '../../package.json'"]
    C --> D["resolveCliVersion()"]
    D -->|"valid string"| E["return packageJson.version"]
    D -->|"empty / non-string\n(defensive guard)"| F["return UNKNOWN_CLI_VERSION\n'0.0.0-unknown'"]
    E --> G["hunk --version output"]
    F --> G
    G --> H["smoke-prebuilt-install.ts\nasserts stdout === packageVersion + newline"]
Loading

Reviews (1): Last reviewed commit: "fix(cli): report packaged version in ins..." | Re-trigger Greptile

@benvinegar benvinegar merged commit 75bfd1e into modem-dev:main Apr 1, 2026
3 checks passed
@benvinegar
Copy link
Copy Markdown
Member

Sweet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants